﻿/*
 * Name:        SnkLabel
 * Description: UI part that acts as an Image Panel
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using Gyvate.Worldspawn;
using Gyvate.Util;

namespace Gyvate.GFX
{
    internal class SnkImgPanel : SnkButton
    {
        protected Image m_spriteImage;
        protected Bitmap m_sprite;

        /*
         * Constructor with Dimensions2D param
         */
        public SnkImgPanel(Game game, Dimensions2d dim)
            : base(game, dim)
        {
        }

        /*
         * Constructor with 2x Vector2f params that will be turned into Dimensions2d
         */
        public SnkImgPanel(Game game, Vector2d pos, Vector2d size)
            : base(game, pos, size)
        {
        }

        /*
         * Sets image
         */
        public void SetImage(string sz)
        {
            if (!m_game.IsPrecached(sz))
                m_game.PrecacheSprite(sz);

            PrecachedSprite spr = m_game.GetPrecachedSprite(sz);

            if (spr == null)
                return;

            m_spriteImage = spr.GetImage();
            m_sprite = spr.GetBitmap();
        }

        /*
         * Draws to buffer
         */
        internal override void Draw()
        {
            if (!IsVisible())
                return;

            if (m_spriteImage == null)
                base.Draw();
            else
                m_game.GetUIParent().DrawImage(m_spriteImage, GetDimensions().pos.x, GetDimensions().pos.y,
                    GetDimensions().size.x, GetDimensions().size.y);
        }
    }
}
